﻿using System;
using System.Collections.Generic;
using System.Configuration;
using System.Web.Http;
using System.Web.Http.Controllers;
using Common.Logging;
using Newtonsoft.Json;
using OutDbContext;
using Senparc.Weixin.MP.AdvancedAPIs;


namespace User.Api.Controllers
{
    [AllowAnonymous]
    public class NotifyController : ApiController
    {
        private static readonly ILog Logger = LogManager.GetLogger(typeof(NotifyController));
        private HzfyWeiXinEntities _ctx;

        protected override void Initialize(HttpControllerContext controllerContext)
        {
            _ctx = new HzfyWeiXinEntities();
            base.Initialize(controllerContext);
        }

        protected override void Dispose(bool disposing)
        {
            _ctx.Dispose();
            base.Dispose(disposing);
        }

        //[HttpGet]
        //[ActionName("CreateQRCode")]
        //public string CreateQrCode(string cardNo)
        //{
        //    var sceneInfo = new SceneInfo();

        //    sceneInfo.CardNo = cardNo;
        //    sceneInfo.CardType = cardNo.Length == 10 ? 0 : (cardNo.Length == 16 ? 1 : 2);
        //    sceneInfo.AddDt = DateTime.Now;
        //    sceneInfo.ExpireDt = DateTime.Now.AddMinutes(30);
        //    _ctx.SceneInfoes.Add(sceneInfo);
        //    _ctx.SaveChanges();

        //    var appId = ConfigurationManager.AppSettings["WeixinAppId"];

        //    try
        //    {
        //        var qrResult = QrCodeApi.Create(appId, 1800, sceneInfo.Id);
        //        return qrResult.url;
        //    }
        //    catch (Exception ex)
        //    {
        //        Logger.ErrorFormat("创建微信二维码时出错，信息：{0}", JsonConvert.SerializeObject(ex));
        //        return "";
        //    }
        //}
    }
}
